package com.example.crm.config.shiro;

import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ShiroConfig {

    @Bean
    public MyShiroRealm myShiroRealm(){
        return  new MyShiroRealm();
    }

    @Bean
    public SecurityManager securityManager(){ //注意package
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        //创建 注入的realm（安全数据源）
        securityManager.setRealm(myShiroRealm());
            return  securityManager;
    }

    @Bean
    public ShiroFilterFactoryBean shiroFilterFactoryBean(){
        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        shiroFilterFactoryBean.setSecurityManager(securityManager());
        return shiroFilterFactoryBean;
    }
}
